package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.TestPointMapper;
import com.example.projectcode.model.Chapter;
import com.example.projectcode.model.Testpoint;
import com.example.projectcode.service.TestPointService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestPointServiceImpl extends ServiceImpl<TestPointMapper, Testpoint> implements TestPointService {
    @Override
    public List<Testpoint> selectAllTestPointByChapid(Integer chapid) {

        QueryWrapper<Testpoint> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("Chapid",chapid);
        List<Testpoint> testPointList = baseMapper.selectList(queryWrapper);

        return testPointList;
    }

    @Override
    public List<Testpoint> selectAllTestpoint() {

        return baseMapper.selectList(new QueryWrapper<Testpoint>());
    }

    @Override
    public int insertTestPoint(Chapter chapter, String testpointName) {
        Testpoint testpoint = new Testpoint();
        testpoint.setChapid(String.valueOf(chapter.getChapid()));
        testpoint.setTestpointname(testpointName);
        return baseMapper.insert(testpoint);
    }

    @Override
    public int deleteTestpointById(Integer testPointId) {
        return baseMapper.delete(new QueryWrapper<Testpoint>().eq("Testpointid",testPointId));
    }
}
